package ZooManager;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* User: James Barker
* Date: 16/08/12
*/
public class EntryAddUI extends JDialog implements ActionListener {
    JTextField entryTypeTextField;


    /**
     * Add Entry UI Constructor
     */
    public EntryAddUI() {
        createEntryDetailPanel();

        this.setTitle("New Entry");
        this.setLocationRelativeTo(this);
        this.setSize(260, 120);
        this.setModal(true);
        this.setVisible(true);
        this.pack();
    }


    public void createEntryDetailPanel() {
        JPanel EntryDetailPanel = new JPanel(new GridLayout(2, 1, 5, 5));
        EntryDetailPanel.setBorder(BorderFactory.createTitledBorder("Add Entry"));
        EntryDetailPanel.add(new JLabel("Entry Type:"));
        entryTypeTextField = new JTextField();
        EntryDetailPanel.add(entryTypeTextField);
        EntryDetailPanel.add(new JLabel(""));
        JButton saveEntryButton = new JButton("Save Entry");
        saveEntryButton.addActionListener(this);
        EntryDetailPanel.add(saveEntryButton);
        this.add(EntryDetailPanel);
    }


    public Entry getNewEntry() {
        return new Entry(entryTypeTextField.getText());
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        this.setVisible(false);
    }
}
